﻿//作者：MrLee
//时间：2011-8-23
//名称：日志查询
Ext.namespace('FantastPlatform', 'FantastPlatform.UI');
FantastPlatform.UI.WorkLogSearchForm = function (config) {
    Ext.apply(this, config);
    var orgStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '../Service/WorkLog.aspx?Action=GetOrganization'
        }),
        reader: new Ext.data.JsonReader({
            root: 'topics',
            totalProperty: 'totalCount',
            id: 'Name',
            fields: ['Id', 'Name']
        }),
        remoteStore: true
    });
    orgStore.load();
    var policeStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '../Service/WorkLog.aspx?Action=GetPoliceByOrgId'
        }),
        reader: new Ext.data.JsonReader({
            root: 'topics',
            totalProperty: 'totalCount',
            id: 'Name',
            fields: ['Id', 'Name']
        }),
        remoteStore: true
    });
    policeStore.load();
    var orgComboBox = new Ext.form.ComboBox({
        fieldLabel: '<font color="red">*</font>&nbsp;&nbsp;成员组',
        name: 'Organization',
        hiddenName: 'OrganizationId',
        store: orgStore,
        displayField: 'Name',
        mode: 'remote',
        valueField: 'Id',
        allowBlank: true,
        editable: false,
        triggerAction: 'all',
        emptyText: '选择部门组',
        readOnly: true,
        width: 130
    });

    var policeComboBox = new Ext.form.ComboBox({
        fieldLabel: '警员名称',
        name: 'PoliceMan',
        hiddenName: 'PoliceMan',
        store: policeStore,
        displayField: 'Name',
        mode: 'remote',
        valueField: 'Id',
        allowBlank: true,
        editable: false,
        triggerAction: 'all',
        emptyText: '选择警员',
        readOnly: true,
        width: 130
    });
    orgComboBox.on('select', function () {

        var Id = orgComboBox.getValue();
        var url = '../Service/WorkLog.aspx?Action=GetPoliceByOrgId';
        policeStore.removeAll();
        policeStore.proxy.conn = { method: 'post', url: url };
        policeStore.reload({ params: { Id: Id} });
    });
    var disp = this.disp;
    this.items = [{
        layout: 'column',
        border: false,
        labelSeparator: '：',
        items: [{
            columnWidth: 1,
            layout: 'form',
            border: false,
            hidden: !eval(disp.Number),
            items: [new Ext.form.TextField({
                fieldLabel: '名称',
                name: 'Name',
                width: 200
            })]
        },
//         {
//            columnWidth: 1,
//            layout: 'form',
//            border: false,
//            hidden: !eval(disp.Name),
//            items: [new Ext.form.TextField({
//                fieldLabel: '标题',
//                name: 'Title',
//                width: 200
//            })]
//        },
         {
            columnWidth: 1,
            layout: 'form',
            border: false,
            hidden: !eval(disp.PolicemanName),
            items: [orgComboBox]
        },
        {
            columnWidth: 1,
            layout: 'form',
            border: false,
            hidden: !eval(disp.PolicemanName),
            items: [policeComboBox]
        }
        ]
    }];
    FantastPlatform.UI.WorkLogSearchForm.superclass.constructor.call(this, {
        bodyStyle: 'padding-top:5px',
        collapsible: true,
        labelAlign: 'right',
        buttonAlign: 'center',
        autoScroll: false
    });

};
Ext.extend(FantastPlatform.UI.WorkLogSearchForm, Ext.form.FormPanel, {
    onRender: function (ct, position) {
        FantastPlatform.UI.WorkLogSearchForm.superclass.onRender.call(this, ct, position);
    },
    submitSearchFormJson: function (form, grid, sender, data) {
        if (form.form.isValid()) {
            if (form.form.getValues().Name == "" && form.form.getValues().Title == "" && form.form.getValues().PoliceMan == "") {
                grid.store.removeAll();
                grid.store.proxy.conn = { method: 'post', url: form.url1 };
                grid.store.load({ params: { start: 0, limit: grid.paperBar.getPageNumber(), dir: '', sort: ''} });
                if (sender)
                    sender.close();
            }
            else {
                var dataStr = Ext.util.JSON.encode(form.form.getValues());
                grid.store.baseParams = {
                    data: dataStr
                }
                grid.store.removeAll();
                grid.store.proxy.conn = { method: 'post', url: form.url };
                grid.store.load({ params: { start: 0, limit: grid.paperBar.getPageNumber(), dir: '', sort: '', data: dataStr} });
                if (sender)
                    sender.close();
            }
        }
    }

});